home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 May / CMCD0504.ISO / Software / Freeware / Programare / gdiplusdelphi / demos / Constructing and Drawing Curves / Drawing Bézier Splines / App2 / GDITEST57.dpr
Encoding:
Text File  |  2003-10-15  |  2.7 KB  |  102 lines

  1. program GDITEST57;
  2.  
  3. uses
  4.   Windows,
  5.   Messages,
  6.   SysUtils,
  7.   GDIPAPI,
  8.   GDIPOBJ;
  9.  
  10.  
  11. Procedure OnPaint(DC: HDC);
  12. var
  13.   graphics : TGPGraphics;
  14.   Pen: TGPPen;
  15. const
  16.   p: array[0..6] of TGPPoint =
  17.    ((x: 10; y: 100),   // start point of first spline
  18.     (x: 75; y: 10),    // first control point of first spline
  19.     (x: 80; y: 50),    // second control point of first spline
  20.  
  21.     (x: 100; y: 150),  // end point of first spline and
  22.                        // start point of second spline
  23.  
  24.     (x: 125; y: 80),   // first control point of second spline
  25.     (x: 175; y: 200),  // second control point of second spline
  26.     (x: 200; y: 80));  // end point of second spline
  27. begin
  28.   graphics := TGPGraphics.Create(DC);
  29.  
  30.   Pen := TGPPen.Create(MakeColor(255, 0, 0, 255));
  31.   graphics.DrawBeziers(pen, PGPPoint(@p), 7);
  32.   Pen.Free;
  33.   graphics.Free;
  34. end;
  35.  
  36.  
  37. function WndProc(Wnd : HWND; message : UINT; wParam : Integer; lParam: Integer) : Integer; stdcall;
  38. var
  39.   Handle: HDC;
  40.   ps: PAINTSTRUCT;
  41. begin
  42.   case message of
  43.     WM_PAINT:
  44.       begin
  45.         Handle := BeginPaint(Wnd, ps);
  46.         OnPaint(Handle);
  47.         EndPaint(Wnd, ps);
  48.         result := 0;
  49.       end;
  50.  
  51.     WM_DESTROY:
  52.       begin
  53.         PostQuitMessage(0);
  54.         result := 0;
  55.       end;
  56.  
  57.    else
  58.       result := DefWindowProc(Wnd, message, wParam, lParam);
  59.    end;
  60. end;
  61.  
  62. var
  63.   hWnd     : THandle;
  64.   Msg      : TMsg;
  65.   wndClass : TWndClass;
  66. begin
  67.    wndClass.style          := CS_HREDRAW or CS_VREDRAW;
  68.    wndClass.lpfnWndProc    := @WndProc;
  69.    wndClass.cbClsExtra     := 0;
  70.    wndClass.cbWndExtra     := 0;
  71.    wndClass.hInstance      := hInstance;
  72.    wndClass.hIcon          := LoadIcon(0, IDI_APPLICATION);
  73.    wndClass.hCursor        := LoadCursor(0, IDC_ARROW);
  74.    wndClass.hbrBackground  := HBRUSH(GetStockObject(WHITE_BRUSH));
  75.    wndClass.lpszMenuName   := nil;
  76.    wndClass.lpszClassName  := 'GettingStarted';
  77.  
  78.    RegisterClass(wndClass);
  79.  
  80.    hWnd := CreateWindow(
  81.       'GettingStarted',       // window class name
  82.       'Drawing BΘzier Splines',       // window caption
  83.       WS_OVERLAPPEDWINDOW,    // window style
  84.       Integer(CW_USEDEFAULT), // initial x position
  85.       Integer(CW_USEDEFAULT), // initial y position
  86.       Integer(CW_USEDEFAULT), // initial x size
  87.       Integer(CW_USEDEFAULT), // initial y size
  88.       0,                      // parent window handle
  89.       0,                      // window menu handle
  90.       hInstance,              // program instance handle
  91.       nil);                   // creation parameters
  92.  
  93.    ShowWindow(hWnd, SW_SHOW);
  94.    UpdateWindow(hWnd);
  95.  
  96.    while(GetMessage(msg, 0, 0, 0)) do
  97.    begin
  98.       TranslateMessage(msg);
  99.       DispatchMessage(msg);
  100.    end;
  101. end.
  102.